package engine.proof.tree;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.Arrays;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

import atom.engine.proof.tree.ProofTreeContentProvider;
import atom.engine.proof.tree.ProofTreeNode;
import atom.tree.ContentProvider;

public class ProofTreeContentProviderTest {
	private ContentProvider<ProofTreeNode> contentProvider;
	private ProofTreeNode root;
	private ProofTreeNode kid1;
	private ProofTreeNode kid2;

	@Before
	public void setUp() {
		contentProvider = new ProofTreeContentProvider();
		createTreeContent();
	}

	/**
	 * The tree structure is the following:
	 * 
	 * A L B L D L C L E L F L H L I L J L L L M L N L G
	 */
	@Test
	public void testHasChildren() {
		assertTrue(contentProvider.hasChildren(root));
		List<ProofTreeNode> children = contentProvider.getChildren(root);
		assertEquals(2, children.size());
		assertEquals(kid1, children.get(0));
		assertEquals(kid2, children.get(1));
	}

	private void createTreeContent() {
		ProofTreeNode n41 = new ProofTreeNode("I", 4);
		ProofTreeNode n42 = new ProofTreeNode("J", 4);
		ProofTreeNode n43 = new ProofTreeNode("L", 4);
		ProofTreeNode n44 = new ProofTreeNode("M", 4);
		ProofTreeNode n45 = new ProofTreeNode("N", 4);
		ProofTreeNode n31 = new ProofTreeNode("H", 3, Arrays.asList(n41, n42,
				n43, n44, n45));
		n41.setParent(n31);
		n42.setParent(n31);
		n43.setParent(n31);
		n44.setParent(n31);
		n45.setParent(n31);
		ProofTreeNode n23 = new ProofTreeNode("F", 2, Arrays.asList(n31));
		n31.setParent(n23);
		ProofTreeNode n24 = new ProofTreeNode("G", 2);
		kid2 = new ProofTreeNode("E", 1, Arrays.asList(n23, n24));
		n23.setParent(kid2);
		n24.setParent(kid2);
		ProofTreeNode n21 = new ProofTreeNode("D", 2);
		ProofTreeNode n22 = new ProofTreeNode("C", 2);
		kid1 = new ProofTreeNode("B", 1, Arrays.asList(n21, n22));
		n21.setParent(kid1);
		n22.setParent(kid1);
		root = new ProofTreeNode("A", 1, Arrays.asList(kid1, kid2));
	}

}
